﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void UpdateKUNDVER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();

            #region====Command====
            or1.CommandText = "UPDATE KUNDVER SET "
                + "KDVMANDANT=:KDVMANDANT,"
                + "KDVKUNDNR=:KDVKUNDNR,"
                + "KDVVB=:KDVVB,"
                + "KDVVG=:KDVVG,"
                + "KDVSTAKZ=:KDVSTAKZ,"
                + "KDVSTADAT=:KDVSTADAT,"
                + "KDVWAEHRSL=:KDVWAEHRSL,"
                + "KDVZAHLBED=:KDVZAHLBED,"
                + "KDVEKON=:KDVEKON,"
                + "KDVKDVKL=:KDVKDVKL,"
                + "KDVVALUTA=:KDVVALUTA,"
                + "KDVSTEUER=:KDVSTEUER,"
                + "KDVLIEFBED=:KDVLIEFBED,"
                + "KDVLANDU=:KDVLANDU,"
                + "KDVPLZU=:KDVPLZU,"
                + "KDVORTU=:KDVORTU,"
                + "KDVBZU=:KDVBZU,"
                + "KDVBZBEZU=:KDVBZBEZU,"
                + "KDVCOUNTRY=:KDVCOUNTRY,"
                + "KDVCITY=:KDVCITY,"
                + "KDVPREISGRP=:KDVPREISGRP,"
                + "KDVMINDST=:KDVMINDST,"
                + "KDVSTDBON=:KDVSTDBON,"
                + "KDVLIEFKOMP=:KDVLIEFKOMP,"
                + "KDVLIEFAUTO=:KDVLIEFAUTO,"
                + "KDVABNGRP=:KDVABNGRP,"
                + "KDVABSSCHL=:KDVABSSCHL,"
                + "KDVMUSTER=:KDVMUSTER,"
                + "KDVKOLLZYKL=:KDVKOLLZYKL,"
                + "KDVBONVON=:KDVBONVON,"
                + "KDVBONIN=:KDVBONIN,"
                + "KDVBONBIS=:KDVBONBIS,"
                + "KDVABRVB=:KDVABRVB,"
                + "KDVABRVG=:KDVABRVG,"
                + "KDVRABABRKZ=:KDVRABABRKZ,"
                + "KDVBONABRKZ=:KDVBONABRKZ,"
                + "KDVGBABRKZ=:KDVGBABRKZ,"
                + "KDVFBABRKZ=:KDVFBABRKZ,"
                + "KDVVBABRKZ=:KDVVBABRKZ,"
                + "KDVGABONA=:KDVGABONA,"
                + "KDVGABONP=:KDVGABONP,"
                + "KDVFIXBONP=:KDVFIXBONP,"
                + "KDVVORBONP=:KDVVORBONP,"
                + "KDVRABART1=:KDVRABART1,"
                + "KDVRABPROZ1=:KDVRABPROZ1,"
                + "KDVRABART2=:KDVRABART2,"
                + "KDVRABPROZ2=:KDVRABPROZ2,"
                + "KDVRABART3=:KDVRABART3,"
                + "KDVRABPROZ3=:KDVRABPROZ3,"
                + "KDVRABART4=:KDVRABART4,"
                + "KDVRABPROZ4=:KDVRABPROZ4,"
                + "KDVRABART5=:KDVRABART5,"
                + "KDVRABPROZ5=:KDVRABPROZ5,"
                + "KDVBONWE1=:KDVBONWE1,"
                + "KDVBONP1=:KDVBONP1,"
                + "KDVBONWE2=:KDVBONWE2,"
                + "KDVBONP2=:KDVBONP2,"
                + "KDVBONWE3=:KDVBONWE3,"
                + "KDVBONP3=:KDVBONP3,"
                + "KDVBONWE4=:KDVBONWE4,"
                + "KDVBONP4=:KDVBONP4,"
                + "KDVBONWE5=:KDVBONWE5,"
                + "KDVBONP5=:KDVBONP5,"
                + "KDVBONWE6=:KDVBONWE6,"
                + "KDVBONP6=:KDVBONP6,"
                + "KDVBONWE7=:KDVBONWE7,"
                + "KDVBONP7=:KDVBONP7,"
                + "KDVBONWE8=:KDVBONWE8,"
                + "KDVBONP8=:KDVBONP8,"
                + "KDVBONWE9=:KDVBONWE9,"
                + "KDVBONP9=:KDVBONP9,"
                + "KDVBONWE10=:KDVBONWE10,"
                + "KDVBONP10=:KDVBONP10,"
                + "KDVUMSGR=:KDVUMSGR,"
                + "KDVDISTRWEG=:KDVDISTRWEG,"
                + "KDVSTATGEB=:KDVSTATGEB,"
                + "KDVSACHB=:KDVSACHB,"
                + "KDVVORBONV1=:KDVVORBONV1,"
                + "KDVVORBONV2=:KDVVORBONV2,"
                + "KDVVORBONV3=:KDVVORBONV3,"
                + "KDVBONLDAT=:KDVBONLDAT,"
                + "KDVVBONLDAT=:KDVVBONLDAT,"
                + "KDVZUREGEL=:KDVZUREGEL,"
                + "KDVZEITRAUM=:KDVZEITRAUM,"
                + "KDVWOCHTAG=:KDVWOCHTAG,"
                + "KDVKZVORW=:KDVKZVORW,"
                + "KDVMONTAG1=:KDVMONTAG1,"
                + "KDVMONTAG2=:KDVMONTAG2,"
                + "KDVDATLSR=:KDVDATLSR,"
                + "KDVVTRNR1=:KDVVTRNR1,"
                + "KDVVTRNR2=:KDVVTRNR2,"
                + "KDVVTRNR3=:KDVVTRNR3,"
                + "KDVVTRNR4=:KDVVTRNR4,"
                + "KDVAZVERB=:KDVAZVERB,"
                + "KDVBASIS=:KDVBASIS,"
                + "KDVSPLITT=:KDVSPLITT,"
                + "KDVMEEH=:KDVMEEH,"
                + "KDVAUFMEEH=:KDVAUFMEEH,"
                + "KDVABRUF=:KDVABRUF,"
                + "KDVZESSIO=:KDVZESSIO,"
                + "KDVMAXWERT=:KDVMAXWERT,"
                + "KDVPREH=:KDVPREH,"
                + "KDVFBPROV=:KDVFBPROV,"
                + "KDVSPLKEY=:KDVSPLKEY,"
                + "KDVFILLER=:KDVFILLER,"
                + "KDVAENDZL=:KDVAENDZL,"
                + "KDVAENDBEN=:KDVAENDBEN,"
                + "KDVAENDDAT=:KDVAENDDAT,"
                + "KDVNEUBEN=:KDVNEUBEN,"
                + "KDVNEUDAT=:KDVNEUDAT"
                + " WHERE  "
                + "  KDVMANDANT=:KDVMANDANT AND KDVKUNDNR=:KDVKUNDNR AND KDVVB=:KDVVB AND KDVVG=:KDVVG";
            #endregion

            #region====Parameters====
            or1.Parameters.Add("KDVMANDANT", OracleType.NVarChar).Value = dwData["KDVMANDANT"].ToString();
            or1.Parameters.Add("KDVKUNDNR", OracleType.NVarChar).Value = dwData["KDVKUNDNR"].ToString();
            or1.Parameters.Add("KDVVB", OracleType.NVarChar).Value = dwData["KDVVB"].ToString();
            or1.Parameters.Add("KDVVG", OracleType.NVarChar).Value = dwData["KDVVG"].ToString();
            or1.Parameters.Add("KDVSTAKZ", OracleType.NVarChar).Value = dwData["KDVSTAKZ"].ToString();
            or1.Parameters.Add("KDVSTADAT", OracleType.NVarChar).Value = dwData["KDVSTADAT"].ToString();
            or1.Parameters.Add("KDVWAEHRSL", OracleType.NVarChar).Value = dwData["KDVWAEHRSL"].ToString();
            or1.Parameters.Add("KDVZAHLBED", OracleType.NVarChar).Value = dwData["KDVZAHLBED"].ToString();
            or1.Parameters.Add("KDVEKON", OracleType.NVarChar).Value = dwData["KDVEKON"].ToString();
            or1.Parameters.Add("KDVKDVKL", OracleType.NVarChar).Value = dwData["KDVKDVKL"].ToString();
            or1.Parameters.Add("KDVVALUTA", OracleType.NVarChar).Value = dwData["KDVVALUTA"].ToString();
            or1.Parameters.Add("KDVSTEUER", OracleType.NVarChar).Value = dwData["KDVSTEUER"].ToString();
            or1.Parameters.Add("KDVLIEFBED", OracleType.NVarChar).Value = dwData["KDVLIEFBED"].ToString();
            or1.Parameters.Add("KDVLANDU", OracleType.NVarChar).Value = dwData["KDVLANDU"].ToString();
            or1.Parameters.Add("KDVPLZU", OracleType.NVarChar).Value = dwData["KDVPLZU"].ToString();
            or1.Parameters.Add("KDVORTU", OracleType.NVarChar).Value = dwData["KDVORTU"].ToString();
            or1.Parameters.Add("KDVBZU", OracleType.NVarChar).Value = dwData["KDVBZU"].ToString();
            or1.Parameters.Add("KDVBZBEZU", OracleType.NVarChar).Value = dwData["KDVBZBEZU"].ToString();
            or1.Parameters.Add("KDVCOUNTRY", OracleType.NVarChar).Value = dwData["KDVCOUNTRY"].ToString();
            or1.Parameters.Add("KDVCITY", OracleType.NVarChar).Value = dwData["KDVCITY"].ToString();
            or1.Parameters.Add("KDVPREISGRP", OracleType.NVarChar).Value = dwData["KDVPREISGRP"].ToString();
            or1.Parameters.Add("KDVMINDST", OracleType.NVarChar).Value = dwData["KDVMINDST"].ToString();
            or1.Parameters.Add("KDVSTDBON", OracleType.NVarChar).Value = dwData["KDVSTDBON"].ToString();
            or1.Parameters.Add("KDVLIEFKOMP", OracleType.NVarChar).Value = dwData["KDVLIEFKOMP"].ToString();
            or1.Parameters.Add("KDVLIEFAUTO", OracleType.NVarChar).Value = dwData["KDVLIEFAUTO"].ToString();
            or1.Parameters.Add("KDVABNGRP", OracleType.NVarChar).Value = dwData["KDVABNGRP"].ToString();
            or1.Parameters.Add("KDVABSSCHL", OracleType.NVarChar).Value = dwData["KDVABSSCHL"].ToString();
            or1.Parameters.Add("KDVMUSTER", OracleType.NVarChar).Value = dwData["KDVMUSTER"].ToString();
            or1.Parameters.Add("KDVKOLLZYKL", OracleType.NVarChar).Value = dwData["KDVKOLLZYKL"].ToString();
            or1.Parameters.Add("KDVBONVON", OracleType.NVarChar).Value = dwData["KDVBONVON"].ToString();
            or1.Parameters.Add("KDVBONIN", OracleType.NVarChar).Value = dwData["KDVBONIN"].ToString();
            or1.Parameters.Add("KDVBONBIS", OracleType.NVarChar).Value = dwData["KDVBONBIS"].ToString();
            or1.Parameters.Add("KDVABRVB", OracleType.NVarChar).Value = dwData["KDVABRVB"].ToString();
            or1.Parameters.Add("KDVABRVG", OracleType.NVarChar).Value = dwData["KDVABRVG"].ToString();
            or1.Parameters.Add("KDVRABABRKZ", OracleType.NVarChar).Value = dwData["KDVRABABRKZ"].ToString();
            or1.Parameters.Add("KDVBONABRKZ", OracleType.NVarChar).Value = dwData["KDVBONABRKZ"].ToString();
            or1.Parameters.Add("KDVGBABRKZ", OracleType.NVarChar).Value = dwData["KDVGBABRKZ"].ToString();
            or1.Parameters.Add("KDVFBABRKZ", OracleType.NVarChar).Value = dwData["KDVFBABRKZ"].ToString();
            or1.Parameters.Add("KDVVBABRKZ", OracleType.NVarChar).Value = dwData["KDVVBABRKZ"].ToString();
            or1.Parameters.Add("KDVGABONA", OracleType.NVarChar).Value = dwData["KDVGABONA"].ToString();
            or1.Parameters.Add("KDVGABONP", OracleType.NVarChar).Value = dwData["KDVGABONP"].ToString();
            or1.Parameters.Add("KDVFIXBONP", OracleType.NVarChar).Value = dwData["KDVFIXBONP"].ToString();
            or1.Parameters.Add("KDVVORBONP", OracleType.NVarChar).Value = dwData["KDVVORBONP"].ToString();
            or1.Parameters.Add("KDVRABART1", OracleType.NVarChar).Value = dwData["KDVRABART1"].ToString();
            or1.Parameters.Add("KDVRABPROZ1", OracleType.NVarChar).Value = dwData["KDVRABPROZ1"].ToString();
            or1.Parameters.Add("KDVRABART2", OracleType.NVarChar).Value = dwData["KDVRABART2"].ToString();
            or1.Parameters.Add("KDVRABPROZ2", OracleType.NVarChar).Value = dwData["KDVRABPROZ2"].ToString();
            or1.Parameters.Add("KDVRABART3", OracleType.NVarChar).Value = dwData["KDVRABART3"].ToString();
            or1.Parameters.Add("KDVRABPROZ3", OracleType.NVarChar).Value = dwData["KDVRABPROZ3"].ToString();
            or1.Parameters.Add("KDVRABART4", OracleType.NVarChar).Value = dwData["KDVRABART4"].ToString();
            or1.Parameters.Add("KDVRABPROZ4", OracleType.NVarChar).Value = dwData["KDVRABPROZ4"].ToString();
            or1.Parameters.Add("KDVRABART5", OracleType.NVarChar).Value = dwData["KDVRABART5"].ToString();
            or1.Parameters.Add("KDVRABPROZ5", OracleType.NVarChar).Value = dwData["KDVRABPROZ5"].ToString();
            or1.Parameters.Add("KDVBONWE1", OracleType.NVarChar).Value = dwData["KDVBONWE1"].ToString();
            or1.Parameters.Add("KDVBONP1", OracleType.NVarChar).Value = dwData["KDVBONP1"].ToString();
            or1.Parameters.Add("KDVBONWE2", OracleType.NVarChar).Value = dwData["KDVBONWE2"].ToString();
            or1.Parameters.Add("KDVBONP2", OracleType.NVarChar).Value = dwData["KDVBONP2"].ToString();
            or1.Parameters.Add("KDVBONWE3", OracleType.NVarChar).Value = dwData["KDVBONWE3"].ToString();
            or1.Parameters.Add("KDVBONP3", OracleType.NVarChar).Value = dwData["KDVBONP3"].ToString();
            or1.Parameters.Add("KDVBONWE4", OracleType.NVarChar).Value = dwData["KDVBONWE4"].ToString();
            or1.Parameters.Add("KDVBONP4", OracleType.NVarChar).Value = dwData["KDVBONP4"].ToString();
            or1.Parameters.Add("KDVBONWE5", OracleType.NVarChar).Value = dwData["KDVBONWE5"].ToString();
            or1.Parameters.Add("KDVBONP5", OracleType.NVarChar).Value = dwData["KDVBONP5"].ToString();
            or1.Parameters.Add("KDVBONWE6", OracleType.NVarChar).Value = dwData["KDVBONWE6"].ToString();
            or1.Parameters.Add("KDVBONP6", OracleType.NVarChar).Value = dwData["KDVBONP6"].ToString();
            or1.Parameters.Add("KDVBONWE7", OracleType.NVarChar).Value = dwData["KDVBONWE7"].ToString();
            or1.Parameters.Add("KDVBONP7", OracleType.NVarChar).Value = dwData["KDVBONP7"].ToString();
            or1.Parameters.Add("KDVBONWE8", OracleType.NVarChar).Value = dwData["KDVBONWE8"].ToString();
            or1.Parameters.Add("KDVBONP8", OracleType.NVarChar).Value = dwData["KDVBONP8"].ToString();
            or1.Parameters.Add("KDVBONWE9", OracleType.NVarChar).Value = dwData["KDVBONWE9"].ToString();
            or1.Parameters.Add("KDVBONP9", OracleType.NVarChar).Value = dwData["KDVBONP9"].ToString();
            or1.Parameters.Add("KDVBONWE10", OracleType.NVarChar).Value = dwData["KDVBONWE10"].ToString();
            or1.Parameters.Add("KDVBONP10", OracleType.NVarChar).Value = dwData["KDVBONP10"].ToString();
            or1.Parameters.Add("KDVUMSGR", OracleType.NVarChar).Value = dwData["KDVUMSGR"].ToString();
            or1.Parameters.Add("KDVDISTRWEG", OracleType.NVarChar).Value = dwData["KDVDISTRWEG"].ToString();
            or1.Parameters.Add("KDVSTATGEB", OracleType.NVarChar).Value = dwData["KDVSTATGEB"].ToString();
            or1.Parameters.Add("KDVSACHB", OracleType.NVarChar).Value = dwData["KDVSACHB"].ToString();
            or1.Parameters.Add("KDVVORBONV1", OracleType.NVarChar).Value = dwData["KDVVORBONV1"].ToString();
            or1.Parameters.Add("KDVVORBONV2", OracleType.NVarChar).Value = dwData["KDVVORBONV2"].ToString();
            or1.Parameters.Add("KDVVORBONV3", OracleType.NVarChar).Value = dwData["KDVVORBONV3"].ToString();
            or1.Parameters.Add("KDVBONLDAT", OracleType.NVarChar).Value = dwData["KDVBONLDAT"].ToString();
            or1.Parameters.Add("KDVVBONLDAT", OracleType.NVarChar).Value = dwData["KDVVBONLDAT"].ToString();
            or1.Parameters.Add("KDVZUREGEL", OracleType.NVarChar).Value = dwData["KDVZUREGEL"].ToString();
            or1.Parameters.Add("KDVZEITRAUM", OracleType.NVarChar).Value = dwData["KDVZEITRAUM"].ToString();
            or1.Parameters.Add("KDVWOCHTAG", OracleType.NVarChar).Value = dwData["KDVWOCHTAG"].ToString();
            or1.Parameters.Add("KDVKZVORW", OracleType.NVarChar).Value = dwData["KDVKZVORW"].ToString();
            or1.Parameters.Add("KDVMONTAG1", OracleType.NVarChar).Value = dwData["KDVMONTAG1"].ToString();
            or1.Parameters.Add("KDVMONTAG2", OracleType.NVarChar).Value = dwData["KDVMONTAG2"].ToString();
            or1.Parameters.Add("KDVDATLSR", OracleType.NVarChar).Value = dwData["KDVDATLSR"].ToString();
            or1.Parameters.Add("KDVVTRNR1", OracleType.NVarChar).Value = dwData["KDVVTRNR1"].ToString();
            or1.Parameters.Add("KDVVTRNR2", OracleType.NVarChar).Value = dwData["KDVVTRNR2"].ToString();
            or1.Parameters.Add("KDVVTRNR3", OracleType.NVarChar).Value = dwData["KDVVTRNR3"].ToString();
            or1.Parameters.Add("KDVVTRNR4", OracleType.NVarChar).Value = dwData["KDVVTRNR4"].ToString();
            or1.Parameters.Add("KDVAZVERB", OracleType.NVarChar).Value = dwData["KDVAZVERB"].ToString();
            or1.Parameters.Add("KDVBASIS", OracleType.NVarChar).Value = dwData["KDVBASIS"].ToString();
            or1.Parameters.Add("KDVSPLITT", OracleType.NVarChar).Value = dwData["KDVSPLITT"].ToString();
            or1.Parameters.Add("KDVMEEH", OracleType.NVarChar).Value = dwData["KDVMEEH"].ToString();
            or1.Parameters.Add("KDVAUFMEEH", OracleType.NVarChar).Value = dwData["KDVAUFMEEH"].ToString();
            or1.Parameters.Add("KDVABRUF", OracleType.NVarChar).Value = dwData["KDVABRUF"].ToString();
            or1.Parameters.Add("KDVZESSIO", OracleType.NVarChar).Value = dwData["KDVZESSIO"].ToString();
            or1.Parameters.Add("KDVMAXWERT", OracleType.NVarChar).Value = dwData["KDVMAXWERT"].ToString();
            or1.Parameters.Add("KDVPREH", OracleType.NVarChar).Value = dwData["KDVPREH"].ToString();
            or1.Parameters.Add("KDVFBPROV", OracleType.NVarChar).Value = dwData["KDVFBPROV"].ToString();
            or1.Parameters.Add("KDVSPLKEY", OracleType.NVarChar).Value = dwData["KDVSPLKEY"].ToString();
            or1.Parameters.Add("KDVFILLER", OracleType.NVarChar).Value = dwData["KDVFILLER"].ToString();
            or1.Parameters.Add("KDVAENDZL", OracleType.NVarChar).Value = dwData["KDVAENDZL"].ToString();
            or1.Parameters.Add("KDVAENDBEN", OracleType.NVarChar).Value = dwData["KDVAENDBEN"].ToString();
            or1.Parameters.Add("KDVAENDDAT", OracleType.NVarChar).Value = dwData["KDVAENDDAT"].ToString();
            or1.Parameters.Add("KDVNEUBEN", OracleType.NVarChar).Value = dwData["KDVNEUBEN"].ToString();
            or1.Parameters.Add("KDVNEUDAT", OracleType.NVarChar).Value = dwData["KDVNEUDAT"].ToString();
            #endregion

            Connect2Proxy(or1);
        }
        public void SaveKUNDVER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryKUNDVER(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapKUNDVER(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertKUNDVER(dwLocal);
            }
            UpdateKUNDVER(dwLocal);

        }
        public DataSet QueryKUNDVER(DataRow dwData, int option = 1)
        {
            DataSet Return = new DataSet();
            DataTable tbLocal = null;
            DataSet Result = new DataSet();
            
                or1 = OracleDB.CreateCommand();
                switch (option)
                {
                    case 2:
                        or1.CommandText = "SELECT * FROM KUNDVER WHERE  "
                            + "  KDVMANDANT=:KDVMANDANT AND KDVKUNDNR=:KDVKUNDNR";
                        or1.Parameters.Add("KDVMANDANT", OracleType.NVarChar).Value = dwData["KDVMANDANT"].ToString();
                        or1.Parameters.Add("KDVKUNDNR", OracleType.NVarChar).Value = dwData["KDVKUNDNR"].ToString();
                        break;
                    case 1:
                    default:
                        or1.CommandText = "SELECT * FROM KUNDVER WHERE  "
                            + "  KDVMANDANT=:KDVMANDANT AND KDVKUNDNR=:KDVKUNDNR AND KDVVB=:KDVVB AND KDVVG=:KDVVG";
                        or1.Parameters.Add("KDVMANDANT", OracleType.NVarChar).Value = dwData["KDVMANDANT"].ToString();
                        or1.Parameters.Add("KDVKUNDNR", OracleType.NVarChar).Value = dwData["KDVKUNDNR"].ToString();
                        or1.Parameters.Add("KDVVB", OracleType.NVarChar).Value = dwData["KDVVB"].ToString();
                        or1.Parameters.Add("KDVVG", OracleType.NVarChar).Value = dwData["KDVVG"].ToString();
                        break;
                }

                Result = Connect2Proxy(or1);
                if (Result.Tables.Count > 0)
                {
                    tbLocal = Result.Tables[0];
                    tbLocal.TableName = "KUNDVER";
                }
                Return.Merge(Result);
            
            return Return;
        }
    }
}
